package com.gs.disk.controller.common;

import com.gs.entity.GeneralPage;
import com.gs.entity.R;
import com.gs.entity.RoleEntity;
import com.gs.disk.service.common.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("disk/common/role")
@Api(tags = "角色")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("roleList")
    @ApiOperation("根据用户信息获取菜单")
    public R<GeneralPage<RoleEntity>> roleList() {
        List<RoleEntity> roleList = roleService.roleList();
        Integer count = roleService.count();
        GeneralPage dto = new GeneralPage();
        dto.setList(roleList);
        dto.setTotal(count);
        return R.ok(dto);
    }

    /**
     * 修改用户权限
     *
     * @param permissionList 权限列表
     * @return 返回影响行数
     */
    @PutMapping("updatePermissions/{roleId}")
    @ApiOperation("根据userId修改用户权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "permissionList", value = "权限列表",paramType = "body"),
    })
    public R updatePermissionsByUserId(@PathVariable Long roleId, @RequestBody List<String> permissionList) {
        roleService.updatePermissions(roleId, permissionList);
        return new R();
    }
}
